package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.hotel.domain.vo.DicProvinceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.hotel.domain.dic.DicProvince;
import com.ktgj.hotel.service.IDicProvinceService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 省、直辖市Controller
 * 
 * @author ruoyi
 * @date 2021-10-28
 */
@ControllerAdvice
@RestController
@RequestMapping("/province")
public class DicProvinceController extends BaseController
{
    @Autowired
    private IDicProvinceService dicProvinceService;

    /**
     * 查询省、直辖市列表
     */
    //@PreAuthorize(hasPermi = "hotel:province:list")
    @GetMapping("/list")
    public TableDataInfo list(DicProvince dicProvince)
    {
        startPage();
        List<DicProvince> list = dicProvinceService.selectDicProvinceList(dicProvince);
        return getDataTable(list);
    }

    /**
     * 导出省、直辖市列表
     */
    //@PreAuthorize(hasPermi = "hotel:province:export")
    @Log(title = "省、直辖市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DicProvince dicProvince) throws IOException
    {
        List<DicProvince> list = dicProvinceService.selectDicProvinceList(dicProvince);
        ExcelUtil<DicProvince> util = new ExcelUtil<DicProvince>(DicProvince.class);
        util.exportExcel(response, list, "省、直辖市数据");
    }

    /**
     * 获取省、直辖市详细信息
     */
    //@PreAuthorize(hasPermi = "hotel:province:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dicProvinceService.selectDicProvinceById(id));
    }

    /**
     * 新增省、直辖市
     */
    //@PreAuthorize(hasPermi = "hotel:province:add")
    @Log(title = "省、直辖市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DicProvince dicProvince)
    {
        return toAjax(dicProvinceService.insertDicProvince(dicProvince));
    }

    /**
     * 修改省、直辖市
     */
    //@PreAuthorize(hasPermi = "hotel:province:edit")
    @Log(title = "省、直辖市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DicProvince dicProvince)
    {
        return toAjax(dicProvinceService.updateDicProvince(dicProvince));
    }

    /**
     * 删除省、直辖市
     */
    //@PreAuthorize(hasPermi = "hotel:province:remove")
    @Log(title = "省、直辖市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dicProvinceService.deleteDicProvinceByIds(ids));
    }

    /**
     * 查询全部省信息(远程)
     * */
    @PostMapping("/allDicProvince")
    public List<DicProvinceVo> allDicProvince(){
        List<DicProvinceVo> dicProvinceVoList = dicProvinceService.selectAllDicProvinceList();
        if (dicProvinceVoList.size() > 0){
            return dicProvinceVoList;
        }
        else {
            return null;
        }
    }
}
